/**
 * 
 */
package com.maywide.jdp.system.spring;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver;

import com.maywide.jdp.core.exception.AppException;

/**
 * @author luoyang
 *
 */
public class ExceptionHandler extends
		AbstractHandlerExceptionResolver {

	/* (non-Javadoc)
	 * @see org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver#doResolveException(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object, java.lang.Exception)
	 */
	@Override
	protected ModelAndView doResolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) {
		response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
		
		Map<String,String> model = new HashMap<String,String>();
		
		String title = "系统异常";
		if(ex instanceof AppException)
			title = "应用异常";
		model.put("title", title);
		
		String message = ex.getLocalizedMessage();
		model.put("message", message);
		
		ModelAndView mv = new ModelAndView("exception",model);
		return mv;
	}

}
